package test;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.util.Calendar;
import java.util.Date;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.appearances.Label;

public class FpsComponent extends GameComponent<ScenaTest> {

	private String text;
	private Date startTime;
	private Label label;
	private int rendersCounter;
	private Thread thread;
	
	public FpsComponent(){
		
		this.thread = new Thread(new FrameThreadSetter(this));
		this.setRendersCounter(0);
		this.text = "0";
		this.label = new Label(new Font(Font.SERIF, Font.PLAIN, 15), Color.BLACK, this.text);
		this.setAppearance(this.label);
		this.startTime = new Date();
		this.thread.start();
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getText() {
		return text;
	}
	
	public void update(DeltaState deltaState) {
		super.update(deltaState);
		//Date now = new Date();
		//if (now.getSeconds() - this.startTime.getSeconds() > 3){
			label.setText("FPS: "+ this.getText());
			this.setAppearance(this.label);
			this.startTime = new Date();
		//}
		
	}
	public void render(Graphics2D graphics) {
		this.getAppearance().render(this, graphics);
		this.setRendersCounter(this.getRendersCounter() + 1);
		
	}

	public Thread getThread() {
		return thread;
	}

	public void setThread(Thread thread) {
		this.thread = thread;
	}

	public int getRendersCounter() {
		return rendersCounter;
	}

	public void setRendersCounter(int rendersCounter) {
		this.rendersCounter = rendersCounter;
	}
}
